<?php
/************************************************************************/
/* FrameWork  test preview                                              */
/* ==================================================================== */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/

$req=$_SERVER["REQUEST_URI"];
if(strstr($req,"vwiki="))
die();

    $file=$page;
	echo"

	<table><tr>
	<td><font size=6>DIFF IN FILE <a href=\"index.php?appname=$appname&page=$file\">$file</a></font><br /></td>\n
	</tr>
	</table>
	<table border='2'>

	<tr>
	    <td style='color: rgb(255, 255, 255); background-color: rgb(204, 51, 0);'><font size='2'><b>filename</b></font></td>
	    <td style='color: rgb(255, 255, 255); background-color: rgb(204, 51, 0);'><font size='2'><b>date update</b></font></td>
	    <td style='color: rgb(255, 255, 255); background-color: rgb(204, 51, 0);'><font size='2'><b>author</b></font></td>
	    <td style='color: rgb(255, 255, 255); background-color: rgb(204, 51, 0);'><font size='2'><b>view</b></font></td>
	</tr>
	";
	if ($lock_dir=@opendir("datas/applications/".apptitle($appname)."/history")) {
	    $i=0;
	    while(($listfile[$i++]=readdir($lock_dir))!=false);
	    for ($i=0;$i<count($listfile)-1;$i++)
		for($i1=$i;$i1<count($listfile)-1;$i1++)
		    if (filemtime("datas/applications/".apptitle($appname)."/history/$listfile[$i]")<filemtime("datas/applications/".apptitle($appname)."/history/$listfile[$i1]")){
			$tmp=$listfile[$i];
			$listfile[$i]=$listfile[$i1];
			$listfile[$i1]=$tmp;
		    }
	    for($i=0;$i<count($listfile)-1;$i++){
		    $versionfile=$listfile[$i];
		    if (strncmp($file.".",$versionfile,strlen($file)+1)==0){
		    echo "<tr>";
		    echo "<td style='color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);'><font size='2'><b>$versionfile</b></td>\n";
		    echo "<td style='color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);'><font size='2'>".date("j F Y g:i a",filemtime("datas/applications/".apptitle($appname)."/history/$versionfile"))."</font></td>\n";
		    $ta=file("datas/applications/".apptitle($appname)."/history/$versionfile");
		    $author=$ta[0];
		    echo "<td style='color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);'><font size='2'>$author</font></td>\n";
		    echo "<td style='color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);'><font size='2'>[<a href='index.php?appname=$appname&page=$file&version_file=$versionfile&action=view'>view</a>]</font></td>\n";
		    echo "</tr>\n";
		}

	    }
	closedir($lock_dir);
	}
	echo "</table>\n";
	echo "</font>\n";
	echo "<hr />\n";


    if ($action=="view"){
	$version_file=$_GET['version_file'];
	echo"
	<table border='2' width='100%'>
	<tr>
	<td style='color: rgb(255, 255, 255); background-color: rgb(0, 204, 51);'><font size='2'><b>Preview of $version_file</b></font></td>
	</table>
	";
        $ta=file("datas/applications/".apptitle($appname)."/history/$version_file");
	for($r=1;$r<count($ta);$r++)
	    echo(rawurldecode($ta[$r]));
	echo"
	<br />
	<table border='2' width='100%'>
	<tr>
	<td style='color: rgb(255, 255, 255); background-color: rgb(0,204, 51);'><font size='2'><b>End of preview of $version_file</b></font></td>
	</table>
	";

    }
?>

</body>
</html>
